
if (Drupal.jsEnabled) {
  $(document).ready(function() {
    banner = Drupal.settings.dev_banner.banner;
    position = Drupal.settings.dev_banner.position;
    if (Drupal.settings.dev_banner.sticky) {
      sticky = ' stickiness ';
    }
    else {
      sticky = '';
    }

    $('body').prepend('<div id="dev-banner" class="' + position + sticky + '">' + banner + '</div>');
    
    // used on config page
    $('#edit-dev-banner-position').change(
      function() {
        // show updating status
        for (var i=0; i < 6; i++) {
          $('#edit-dev-banner-image-set-' + i + '-wrapper .images').html('<div style="text-decoration: blink;">updating...</div>');
        }

        // get position value from select list
        var pos = $("#edit-dev-banner-position option:selected").val();
        $.getJSON(Drupal.settings.basePath + 'dev_banner/refresh/' + pos, function(data) {
          var offset = 0;
          for (var idx in data) {
            $('#edit-dev-banner-image-set-' + offset + '-wrapper .images').html(data[idx]);
            offset++;
          }
        });
      }
    );
  });
}
